package com.zang.blogz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zang.blogz.constant.SecurityConstant;
import com.zang.blogz.entity.Resource;
import com.zang.blogz.mapper.ResourceMapper;
import com.zang.blogz.model.output.ResourceVO;
import com.zang.blogz.service.ResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zang.blogz.service.RoleResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 朵橙i
 * @since 2022-06-17
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    @Autowired
    private RoleResourceService roleResourceService;



    @Override
    public List<Resource> queryResourceByRoleId(Integer roleId) {

        LambdaQueryWrapper<Resource> queryWrapper = new LambdaQueryWrapper<>();

        List<Integer> resourceList = roleResourceService.getResourceIdByRoleId(roleId);

        queryWrapper.ne(Resource::getParentId, SecurityConstant.IS_PARENTS);
        queryWrapper.in(Resource::getId, resourceList);



        return list(queryWrapper);
    }

    @Override
    public List<ResourceVO> getResourceTree() {
        
        return resourceMapper.getResourceTree();

    }




}
